﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _8_2 : System.Web.UI.Page
{
    string categoryName;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            categoryDataBind();
            categoryName = DrDoCategory.SelectedValue;
            productDataBind();
        }
    }

    /// <summary>
    /// DropDownList中显示数据
    /// </summary>
    protected void categoryDataBind()
    {
        MyPetShopDataContext db = new MyPetShopDataContext();
        var result = from c in db.Category
                     select c.Name;
        DrDoCategory.DataSource = result;
        DrDoCategory.DataBind();
    
    }

    /// <summary>
    /// GirdView中显示数据
    /// </summary>
    protected void productDataBind()
    {
        MyPetShopDataContext db = new MyPetShopDataContext();
        var result = from p in db.Product
                     join c in db.Category on p.CategoryId equals c.CategoryId
                     where c.Name == categoryName
                     select p;
        GVData.DataSource = result;
        GVData.DataBind();
    }


    protected void DrDoCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        categoryName = DrDoCategory.SelectedValue;
        productDataBind();
    }
}